package comparator;

interface Comparable{
     void compare_total(Staff[] staffs);
    void compare_group(Staff[] staffs);
}


class Staff implements Comparable{
    String id;
    String name;
    String sex;
    int t;
    int s;

    public Staff(){
    }

    public Staff(String id, String name, String sex, int t, int s) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.t = t;
        this.s = s;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getT() {
        return t;
    }

    public void setT(int t) {
        this.t = t;
    }

    public int getS() {
        return s;
    }

    public void setS(int s) {
        this.s = s;
    }

    public void compare_total(Staff[] staffs){
        Staff  temp = new Staff();
        int flag = 1;
        for(int i=0;i<staffs.length ;i++){
            if(flag == 0)
                break;
            flag = 0;
            for(int k=1;k<staffs.length-i;k++) {
                if ((staffs[k].t+staffs[k].s) < (staffs[k - 1].t+staffs[k-1].s)) {
                    temp = staffs[k];
                    staffs[k]= staffs[k - 1];
                    staffs[k - 1] = temp;
                }
                flag = 1;
            }

        }
    }

    public void compare_group(Staff[] staffs) {
        Staff  temp = new Staff();
        int flag = 1;
        for(int i=0;i<staffs.length ;i++){
            if(flag == 0)
                break;
            flag = 0;
            for(int k=1;k<staffs.length-i;k++) {
                if (staffs[k].t < staffs[k - 1].t) {
                    temp = staffs[k];
                    staffs[k]= staffs[k - 1];
                    staffs[k - 1] = temp;
                }
                flag = 1;
            }


        }
    }



}
public class Main {
    public static void main(String[] args) {
        Staff []staffs = new Staff[]{new Staff("1","职工1","female",500,400),
                new Staff("2","职工2","female",400,600),
                new Staff("3","职工3","male",600,300),
                new Staff("4","职工4","female",800,200),
                new Staff("5","职工5","male",500,700)};
        Staff s1 = new Staff();
        s1.compare_total(staffs);
        System.out.println("编号,团险,个险,姓名,性别");
        for (Staff staff : staffs) {
            System.out.printf("%s,%d,%d,%s,%s\n", staff.id, staff.t, staff.s, staff.name, staff.sex);
        }
        Staff s2 = new Staff();
        s2.compare_group(staffs);
        System.out.println("编号,团险,个险,姓名,性别");
        for (Staff staff : staffs) {
            System.out.printf("%s,%d,%d,%s,%s\n", staff.id, staff.t, staff.s, staff.name, staff.sex);
        }
    }



}
